#ifndef GPRS_FACTORY_H
#define GPRS_FACTORY_H

#include "gprsstruct.h"
#include "ComStruct.h"

class CGPRSFactory
{
public:
	CGPRSFactory();
	~CGPRSFactory();

public:
	// Receive
	int analyDataDatagramStack(SGPRSHead* pGPRSHead,  CBattStack* pBattStack, char* pData, int iLen); 
	int analyDataDatagramBank(SGPRSHead* pGPRSHead, CBattBank* pBattBank, CBankAlarm* pBankAlarm, char* pData, int iLen); 
	int prepareExcepDatagram(char* pDataBuf, SGPRSHead* pGPRSHead, int iErrCode);

	// Send
	int prepareDatagramStack(quint8 uCmdType, CBattStack* pBattStack, char* pDataBuf);
	int prepareDatagramBank(quint8 uCmdType, CBattBank* pBattBank, CBankAlarm* pBattAlarm, char* pDataBuf, quint8 uModbusAddr);
	int prepareDatagramBAComInputReg(quint8 uaBAIndex, quint16* pComInputRegData, char* pDataBuf);
	int prepareDatagramCmd(quint8 uCmdType, CBattBank* pBattBank, char* pDataBuf, quint8 uModbusAddr);	

	int addParam2Buffer(char* pData, quint32 uiParamVal);
	int addParam2Buffer(char* pData, quint16 uiParamVal);
	int addParam2Buffer(char* pData, float fParamVal);

	int addCRC2Buffer(uchar *pData, int iLen);

	quint16 CRC16(uchar *pData, quint16 usLen);
	int getParamFromBuffer(char* pData, quint16& uiParamVal);

private:		
	int getParamFromBuffer(char* pData, quint32& uiParamVal);
	int getParamFromBuffer(char* pData, float& fParamVal);	
};

#endif // GPRS_FACTORY_H
